<?php namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;


/**
 * App\Fields
 *
 * @property integer $id
 * @property string $field
 * @property string $deleted_at
 * @property \Carbon\Carbon $created_at
 * @property \Carbon\Carbon $updated_at
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Project[] $project_x_fields
 * @method static \Illuminate\Database\Query\Builder|\App\Fields whereId($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Fields whereField($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Fields whereDeletedAt($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Fields whereCreatedAt($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Fields whereUpdatedAt($value)
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\InvestOrg[] $investorg_x_fields
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Investor[] $investor_x_fields
 * @method static \Illuminate\Database\Query\Builder|\App\Fields like($field, $value)
 */
class Fields extends Model{

    protected $table = 'fields';
    protected $fillable  = ['id', 'field'];
    use SoftDeletes;

    /** 行业领域-项目关系 */
    public function project_x_fields()
    {
        return $this->belongsToMany('App\Project','project_fields','field_id','project_id');
    }

    /** 关联投资机构-投资领域 */
    public function investorg_x_fields()
    {
        return $this->belongsToMany('App\InvestOrg' , 'invest_fields' , 'field_id' , 'org_id');
    }

    /** 关联投资人-投资领域 */
    public function investor_x_fields()
    {
        return $this->belongsToMany('App\Fields','invest_fields','field_id','investor_id');

    }

    public function scopeLike($query, $field, $value)
    {
        return $query->where($field, 'LIKE', "%$value%");
    }
}